//
//  RigisterView.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/10/14.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "RigisterView.h"

@interface RigisterView()

@property (nonatomic,copy)NSString *content;

@end

@implementation RigisterView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        self.frame = CGRectMake(0, 0, ScreenWidth, 5000);
        [self loadData];
        
        
    }
    return self;
}

- (void)loadUI{
    UIWebView *web = [[UIWebView alloc] initWithFrame:CGRectMake(20, 150, ScreenWidth-40, ScreenHeight-300)];
    //加载html文本
    [web loadHTMLString:_content baseURL:nil];
    [self addSubview:web];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = [UIColor whiteColor];
    btn.frame = CGRectMake(20, web.frame.origin.y+web.frame.size.height, ScreenWidth-40, 40);
    [btn setTitle:@"确定" forState:UIControlStateNormal];
    [btn setTitleColor:COLOR_RGB(17, 100, 253, 1) forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    
}

- (void)click{
    [self removeFromSuperview];
}

-(void)show{
    self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
    __weak RigisterView *my = self;
    [UIView animateWithDuration:0.3 animations:^{
        my.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
    }];
}

- (void)loadData{
    NSString *url = [NSString stringWithFormat:@"%@/App/Agreement/registration",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        //NSLog(@"res:%@",responseObject);
        _content = [[responseObject objectForKey:@"result"] objectForKey:@"content"];
        [self loadUI];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self removeFromSuperview];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
